package com.example.yadmin.sys.controller;

import com.example.yadmin.common.vo.Result;
import com.example.yadmin.sys.entity.Goods;
import com.example.yadmin.sys.entity.User;
import com.example.yadmin.sys.entity.UserRole;
import com.example.yadmin.sys.service.IUserRoleService;
import com.example.yadmin.sys.service.IUserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ag
 * @since 2023-10-09
 */
@Api(tags = {"用户角色关系列表"})
@RestController
@RequestMapping("/userRole")
public class UserRoleController {
    @Autowired
    private IUserRoleService userRoleService;

    @GetMapping("/all")
    public Result<List<UserRole>> getAllUser(){
        List<UserRole> list = userRoleService.list();
        return Result.success(list,"查询成功");
    }

    //根据用户id查询用户的角色列表
    @GetMapping("/info")
    public Result<List<UserRole>> getUserRoleListByUserId(@RequestParam(value = "userId") Integer userId){
        List<UserRole> list = userRoleService.getUserRoleListByUserId(userId);
        return Result.success(list);
    }

    //增
    @PostMapping
    public Result<?> addUserRole(@RequestBody UserRole userRole){
        userRoleService.addUserRole(userRole);
        return Result.success("新增权限成功");
    }

    //改
    @PutMapping
    public Result<?> updateUserRole(@RequestBody UserRole userRole){
        userRoleService.updateUserRole(userRole);
        return Result.success("修改权限成功");
    }
}
